package com.example.attendancesystem_1_8;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.attendancesystem_1_8.R;
import com.example.attendancesystem_1_8.entity.DakaTime;

import java.util.ArrayList;
import java.util.List;


public class MyListAdapter extends BaseAdapter {
    private Context mContext;
    private LayoutInflater mLayoutInflater;
    //Data
    private List<DakaTime> list_setTime = new ArrayList<DakaTime>();

    MyListAdapter(List<DakaTime> list_setTime, Context context) {
        this.mContext = context;
        this.list_setTime = list_setTime;
        mLayoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list_setTime.size();
    }

    @Override
    public Object getItem(int position) {
        return list_setTime.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    static class ViewHolder {
        public ImageView imageView;
        public TextView tvTitle, tvTime, tvContent;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = mLayoutInflater.inflate(R.layout.layout_list_item, null);
            holder = new ViewHolder();
            holder.imageView = convertView.findViewById(R.id.iv);
            holder.tvTitle = convertView.findViewById(R.id.tv_title);
            holder.tvTime = convertView.findViewById(R.id.tv_time);
            holder.tvContent = convertView.findViewById(R.id.tv_content);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        //holder.tvTitle.setText("打卡时间：");
        //holder.tvTime.setText("2088-08-08");
        //holder.tvContent.setText("类型：上班");
        //Glide.with(mContext).load("https://www.baidu.com/img/bd_logo1.png?where=super").into(holder.imageView);

        //set list Data
        holder.imageView.setImageResource(R.drawable.picture1);
        String ChartId = (list_setTime.get(position).getLeaderId()) + "";
        holder.tvTitle.setText("设定人： \t" + ChartId);
        //list_setTime.get(position).getLeaderId()
        String ChartTime = list_setTime.get(position).getHour() + ":" + list_setTime.get(position).getMinute();
        holder.tvTime.setText("打卡时间：\t" + ChartTime);
        //list_setTime.get(position).getHour() + "-" + list_setTime.get(position).getMinute()
        String ChartWeek = list_setTime.get(position).getWeek() + "";
        holder.tvContent.setText("周：   \t" + ChartWeek);
        //list_setTime.get(position).getWeek().toString()

        return convertView;
    }
}